package com.home.moon.util;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author 72492
 */
@Component
@AllArgsConstructor
public class RedisUtil {
    private final RedisTemplate<Object,Object> redisTemplate;

    /**
     * 查询
     * @param key
     * @return
     */
    public Object get(String key){
        Object value = redisTemplate.opsForValue().get(key);
        return value;
    }

    /**
     * 插入
     * @param key
     * @param value
     * @param timeout
     * @param unit
     */
    public void put(String key,Object value,long timeout,TimeUnit unit){
        redisTemplate.opsForValue().set(key,value,timeout,unit);
    }

    /**
     * 删除
     * @param key
     */
    public void delete(String key){
        redisTemplate.delete(key);
    }

}
